<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require './api.class.php';


//$str='a:1:{s:5:"order";a:18:{s:3:"ref";s:16:"2016101714513849";s:12:"channel_code";s:2:"ec";s:13:"trade_pattern";s:2:"b1";s:10:"date_order";s:19:"2016-10-17 14:16:16";s:5:"buyer";s:17:"2973738594@qq.com";s:6:"seller";s:16:"532427264@qq.com";s:12:"receive_info";s:112:"黄翠连|17783067698|中国|重庆|重庆市|南岸区|重庆市南岸区学府大道33号交科院10栋|530200";s:18:"total_import_taxes";s:5:"8.810";s:14:"amount_untaxed";s:6:"69.000";s:12:"amount_total";s:6:"82.810";s:12:"delivery_fee";s:5:"5.000";s:12:"buyer_reg_no";s:17:"2973738594@qq.com";s:10:"buyer_name";s:9:"黄翠连";s:13:"buyer_id_type";s:1:"1";s:13:"buyer_id_card";s:18:"450121199101144524";s:10:"order_line";a:1:{i:0;a:7:{s:3:"sku";s:8:"P0042007";s:4:"name";s:48:"(保税)德国 Lavera 柠檬平衡洗发露200ml";s:5:"price";d:69;s:3:"num";i:1;s:7:"tax_fee";s:5:"8.806";s:9:"sub_total";s:6:"77.806";s:17:"sub_total_untaxed";d:69;}}s:12:"payment_line";a:1:{i:0;a:3:{s:15:"payment_account";s:6:"alipay";s:9:"payamount";d:82.810000000000002;s:10:"payment_no";s:14:"14766849855438";}}s:7:"ebpCode";s:10:"50089609A8";}}';
//var_export(unserialize($str));die;
//trade_add();

trade_return();
function trade_add() {
    $trade_data = array(
        'order' =>
        array(
            'ref' => '20161017145131299',
            'channel_code' => 'ec',
            'trade_pattern' => 'b1',
            'date_order' => '2016-10-17 14:16:16',
            'buyer' => '2973738594@qq.com',
            'seller' => '532427264@qq.com',
            'receive_info' => '黄翠连|17783067698|中国|重庆|重庆市|南岸区|重庆市南岸区学府大道33号交科院10栋|530200',
            'total_import_taxes' => '8.810',
            'amount_untaxed' => '69.000',
            'amount_total' => '82.810',
            'delivery_fee' => '5.000',
            'buyer_reg_no' => '2973738594@qq.com',
            'buyer_name' => '黄翠连',
            'buyer_id_type' => '1',
            'buyer_id_card' => '450121199101144524',
            'order_line' =>
            array(
                0 =>
                array(
                    'sku' => 'P0042007',
                    'name' => '(保税)德国 Lavera 柠檬平衡洗发露200ml',
                    'price' => 69,
                    'num' => 1,
                    'tax_fee' => '8.806',
                    'sub_total' => '77.806',
                    'sub_total_untaxed' => 69,
                ),
            ),
            'payment_line' =>
            array(
                0 =>
                array(
                    'payment_account' => 'alipay',
                    'payamount' => 82.81,
                    'payment_no' => '14766849855438',
                ),
            ),
            'ebpCode' => '50089609A8',
        ),
    );

    $api = new api();
    $api->adddata("info_string", json_encode($trade_data));
    $api->adddata("method", "Order.trade_add");
    $res = $api->send();
    var_dump($res);
}

function trade_return(){
    $api=new api();
    $api->adddata("ref", "2016120611028907");
    $api->adddata("method", "Order.trade_return");
    $res = $api->send();
    var_dump($res);
}
